<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of banner
 * 
 * @author Subha Sundar Das (subhasundar.das@gmail.com)
 */
class Banner extends MY_Controller {

    //put your code here


    function banner() {
        parent :: __construct();
        $this->load->model('pickup_model');
        $this->load->model('banner_model');

        $this->template->set_theme('admin');
        $this->template->set_layout('admin_layout');
        $this->commoncall->check_admin_login();
    }

    function index() {
        $data['pickup']['banner_size'] = $this->pickup_model->get_pickup(15);
        $data['banners']['info'] = $this->banner_model->get_banners();
        $this->template->title('Banner Management', $this->settings_model->get_setting('webtitle'))
                ->set_partial('admin_header', 'header/admin_header')
                ->set_partial('admin_left_menu', 'sidebar/admin_left_menu')
                ->build('pages/admin_banner', $data);
    }

    function insert() {

        if ($_FILES['userfile']['error'] == 0) {
            $ext = preg_replace("/.*\.([^.]+)$/", "\\1", $_FILES['userfile']['name']);
            $filename = date('dmyhms') . "." . $ext;
            //print $filename;
            //exit();
            $config['file_name'] = $filename;
            $config['upload_path'] = './assets/images/data/advertisement/';
            $config['allowed_types'] = 'gif|png|jpg';
            $config['overwrite'] = true;
            $config['remove_spaces'] = true;
            $this->load->library('upload', $config);
            if ($this->upload->do_upload('userfile')) {
                //--Add data to table --//


                $post_array = array(
                    'size' => $_POST['banner_size'],
                    'file' => $filename,
                    'link' => $_POST['link']
                );

                if ($this->input->post('banner_size')) {
                    $this->banner_model->insert_banner($post_array);
                    $this->session->set_flashdata('message', "Banner Uploaded..");
                    redirect('admin/banner');
                } else {
                    $this->session->set_flashdata('message', "Error! Insert Banner");
                    redirect('admin/banner');
                }
            } else {
                $this->session->set_flashdata('message', "Error! Insert Banner");
                redirect('admin/banner');
            }
        } else {
            $this->session->set_flashdata('message', "Error! Select Size and Banner Image");
            redirect('admin/banner');
        }
    }
    
    //-- Banner Delete (Subha)--//
    function delete($id,$image_file) {
        $this->banner_model->delete_banner($id,$image_file);
        redirect('admin/banner');
    }
}

?>
